let {form,$,layer} = layui;
form.verify({
    username:function(value,item){
        if(!/^\w{6,20}$/.test(value)){
            return "用户名输入有误"
        }
        
        let str;
        $.ajax({
            type:"post",
            url:"/users/usernameExist",
            async:false,
            data:{
                username:value
            },
            success(res){
                if(res.status == 0){
                    str = "用户名已存在";
                }
            }
        });
        return str;
        

    },
    pwd:[/^.{6,}$/,"密码格式不正确"]
});
form.on("submit(regSubmit)",function(data){
    console.log(data.field);
    console.log(form.val("regForm"));
    $.ajax({
        type:"post",
        url:"/users/reg",
        data:data.field,
        success(res){
            console.log(res);
            layer.alert("注册成功",function(){
                location.href = "#login";
            });
        }
    });
    return false;
});